import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:test01/okhttp_test/page/indexlogin/position_page.dart';
import 'package:test01/okhttp_test/pojo/saveBasicFitnessInfo_pojo.dart';
import 'package:test01/okhttp_test/util/request_http.dart';

/*
*
* 登录界面-------------难度选择
*
*
* */
class DifficultyPage extends StatefulWidget {
  const DifficultyPage({Key key}) : super(key: key);

  @override
  _DifficultyPageState createState() => _DifficultyPageState();
}

class _DifficultyPageState extends State<DifficultyPage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar:  AppBar(
          leading: GestureDetector(
            onTap: (){
              Navigator.pop(context);
            },
            child: Icon(
              Icons.arrow_back_ios,
              size: 28,
              color: Colors.black,
            ),
          ),
          backgroundColor: Colors.white,
          elevation: 0,
          automaticallyImplyLeading: true,
        ),
        body: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(left: 41, top: 42.5),
                child: Text(
                  "选择适合你的难度",
                  style: TextStyle(
                      fontSize: 23, color: Color.fromRGBO(17, 17, 17, 1)),
                ),
              ),
              Container(
                margin: EdgeInsets.only(left: 41, top: 12),
                child: Text(
                  "我们将以此为你推荐训练计划，让你一试身手",
                  style: TextStyle(
                      fontSize: 14, color: Color.fromRGBO(51, 51, 51, 1)),
                ),
              ),
              DifficultyList(),
            ]));
  }
}


class DifficultyList extends StatefulWidget {
  const DifficultyList({Key key}) : super(key: key);

  @override
  _DifficultyListState createState() => _DifficultyListState();
}

///类型选择
class _DifficultyListState extends State<DifficultyList> {
  //初始化数据
  List goals_list=["初级","中级","高级"];
  String goals_describe="从零开始，通过适应性训练，为塑造肌肉线条打好基础";
  //数据被单击的下标
  int click_index;

  SaveBasicFitnessInfo _saveBasicFitnessInfo=SaveBasicFitnessInfo();

  void goalsClick(int clickindex){
    click_index=clickindex;
    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return  Container(
      margin: EdgeInsets.only(top: 12,left: 41),
      width: MediaQuery.of(context).size.width-82,
      height: 357,
      child: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return GestureDetector(
            onTap: () async{
              goalsClick(index);

              _saveBasicFitnessInfo.level=click_index;
              bool xx=await saveBasicFitnessInfo(_saveBasicFitnessInfo,"/appuser/web/user/saveBasicFitnessInfo");
              if(xx){
                Navigator.push(context, MaterialPageRoute(builder: (context) {
                  return PositionPage();
                }));
              }
            },
            child:click_index==index?
            Container(
              color: Color.fromRGBO(204, 204, 204, 1).withOpacity(0.16),
              margin: EdgeInsets.only(top:12,bottom: 12),
              height: 95,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(left: 12),
                    child:  Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            Container(
                              margin: EdgeInsets.only(left: 12,top: 10),
                              child: Text("L${index+1}",style: TextStyle(fontSize: 23,color: Color.fromRGBO(17, 17, 17, 1)),),
                            ),
                            Container(
                              margin: EdgeInsets.only(left: 3,top: 16),
                              child: Text("${goals_list[index]}",style: TextStyle(fontSize: 16,color: Color.fromRGBO(17, 17, 17, 1))),
                            ),
                          ],
                        ),

                        Container(
                          width: MediaQuery.of(context).size.width-108-53,
                          margin: EdgeInsets.only(left: 12,top: 7),
                          child: Text("$goals_describe",style: TextStyle(
                            fontSize: 12,color: Color.fromRGBO(153, 153, 153, 1),
                          ),
                            overflow: TextOverflow.ellipsis,
                            maxLines: 2,

                          ),
                        ),
                      ],
                    ),
                  ),
                  Spacer(),
                  Container(
                    alignment: Alignment.center,
                    child: Icon(Icons.arrow_forward_ios_sharp,size: 12,color: Color.fromRGBO(204, 204, 204, 1),),
                  ),
                  SizedBox(width: 5,)
                ],
              ),
            ):
            Container(
              margin: EdgeInsets.only(top:12,bottom: 12),
              height: 95,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(left: 12),
                    child:  Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            Container(
                              margin: EdgeInsets.only(left: 12,top: 10),
                              child: Text("L${index+1}",style: TextStyle(fontSize: 23,color: Color.fromRGBO(102, 102, 102, 1)),),
                            ),
                            Container(
                              margin: EdgeInsets.only(left: 3,top: 16),
                              child: Text("${goals_list[index]}",style: TextStyle(fontSize: 16,color: Color.fromRGBO(102, 102, 102, 1))),
                            ),
                          ],
                        ),

                        Container(
                          width: MediaQuery.of(context).size.width-108-53,
                          margin: EdgeInsets.only(left: 12,top: 7),
                          child: Text("$goals_describe",style: TextStyle(
                            fontSize: 12,color: Color.fromRGBO(153, 153, 153, 1),
                          ),
                            overflow: TextOverflow.ellipsis,
                            maxLines: 2,

                          ),
                        ),
                      ],
                    ),
                  ),
                  Spacer(),
                  Container(
                    alignment: Alignment.center,
                    child: Icon(Icons.arrow_forward_ios_sharp,size: 12,color: Color.fromRGBO(204, 204, 204, 1),),
                  ),
                  SizedBox(width: 5,)
                ],
              ),
            ),
          );
        },
        itemCount: goals_list.length,
      ),
    );
  }
}
